package com.yilin.medical.activity;

import java.lang.reflect.Field;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.ImageView;
import android.widget.TextView;

import com.yilin.medical.R;
import com.yilin.medical.activity.WoDeHuiZhenActivity.MyPagerAdapter;
import com.yilin.medical.fragment.TiJiaoGeiWoZhuanZhenFragment;
import com.yilin.medical.fragment.WoFaBuHuiZhenFragment;
import com.yilin.medical.fragment.WoTiJiaoZhuanZhenFragment;
import com.yilin.medical.views.PagerSlidingTabStrip;

public class WoDeZhuanZhenActivity extends BaseActivity {




	private Context context;
	
	private WoTiJiaoZhuanZhenFragment shouCangKeChengFragment;
	private TiJiaoGeiWoZhuanZhenFragment yiZhiFuKeChengFragment;
	private PagerSlidingTabStrip tabs;
	private DisplayMetrics dm;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentViewWithTitle(R.layout.activity_wodehuizhen);
		context = this;
		setOverflowShowingAlways();
		dm = getResources().getDisplayMetrics();
		ViewPager pager = (ViewPager) findViewById(R.id.pager);
		tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
		pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
		tabs.setViewPager(pager);
		setTabsValue();
		initView();
		registerLintener();
	}

	private void initView() {
		mTitle.getTitle().setText("我的转诊");
	}



	private void registerLintener() {
	}
	
	public class MyPagerAdapter extends FragmentPagerAdapter {

		public MyPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		private final String[] titles = { "我提交的", "提交给我的"};

		@Override
		public CharSequence getPageTitle(int position) {
			return titles[position];
		}

		@Override
		public int getCount() {
			return titles.length;
		}
		
		@Override
		public Fragment getItem(int position) {
			switch (position) {
			case 0:
				if (shouCangKeChengFragment == null) {
					shouCangKeChengFragment = new WoTiJiaoZhuanZhenFragment();
				}
				return shouCangKeChengFragment;
			case 1:
				if (yiZhiFuKeChengFragment == null) {
					yiZhiFuKeChengFragment = new TiJiaoGeiWoZhuanZhenFragment();
				}
				return yiZhiFuKeChengFragment;
			default:
				return null;
			}
		}

	}
	private void setOverflowShowingAlways() {
		try {
			ViewConfiguration config = ViewConfiguration.get(this);
			Field menuKeyField = ViewConfiguration.class
					.getDeclaredField("sHasPermanentMenuKey");
			menuKeyField.setAccessible(true);
			menuKeyField.setBoolean(config, true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void setTabsValue() {
		// 设置Tab是自动填充满屏幕的
		tabs.setShouldExpand(true);
		// 设置Tab的分割线是透明的
		tabs.setDividerColor(Color.TRANSPARENT);
		// 设置Tab底部线的高度
		tabs.setUnderlineHeight((int) TypedValue.applyDimension(
				TypedValue.COMPLEX_UNIT_DIP, 1, dm));
		// 设置Tab Indicator的高度
		tabs.setIndicatorHeight((int) TypedValue.applyDimension(
				TypedValue.COMPLEX_UNIT_DIP, 2, dm));
		// 设置Tab标题文字的大小
		tabs.setTextSize((int) TypedValue.applyDimension(
				TypedValue.COMPLEX_UNIT_SP, 16, dm));
		// 设置Tab Indicator的颜色
		tabs.setIndicatorColor(Color.parseColor("#2995D3"));
		// 设置选中Tab文字的颜色 (这是我自定义的一个方法)
		tabs.setSelectedTextColor(Color.parseColor("#2995D3"));
		// 取消点击Tab时的背景色
		tabs.setTabBackground(0);
	}
	@Override
	public void onClick(View v) {
		Intent intent;
		super.onClick(v);
		switch (v.getId()) {
		}
	}

	





}
